<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>采集进度</title>
    <!--在IE浏览器中运行最新的渲染模式-->
    <meta http-equiv="X-UA-Compatible" content="IE-Edge">
    <!--初始化移动浏览器显示-->
    <meta name="viewport" content="width-device-width,inital-scale=1">
    <!-- Bootstrap Core CSS -->
    <link href="//cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- jQuery -->
    <script src="//cdn.jsdelivr.net/npm/jquery@2.1.4/dist/jquery.min.js"></script>
    <script src="http://real.hffd.gov.cn/Content/js/jquery-1.8.2.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="//cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var value = 0;
            var page = 1;
            var time = 10000;
            //进度条复位函数
            function reset( ) {
                value = 0
                $("#prog").removeClass("progress-bar-success").css("width","0%").text("等待启动");
                //setTimeout(increment,5000);
            }
            //百分数增加，0-30时为红色，30-60为黄色，60-90为蓝色，>90为绿色
            function increment( ) {
                $.post('/house/building_info/allCollect',{'page':page},function (e) {
                    if(e.code == 200){
                        value += e.progress;
                        page  +=1;
                        if((e.totalPage  / page ) < 1 ){
                            return false;
                        }
                    }
                },'json');
                $("#prog").css("width",value + "%").text(value + "%");
                if (value>=0 && value<=30) {
                    $("#prog").addClass("progress-bar-danger");
                }
                else if (value>=30 && value <=60) {
                    $("#prog").removeClass("progress-bar-danger");
                    $("#prog").addClass("progress-bar-warning");
                }
                else if (value>=60 && value <=90) {
                    $("#prog").removeClass("progress-bar-warning");
                    $("#prog").addClass("progress-bar-info");
                }
                else if(value >= 90 && value<100) {
                    $("#prog").removeClass("progress-bar-info");
                    $("#prog").addClass("progress-bar-success");
                }
                else{
                    setTimeout(reset,3000);
                    return;

                }

                st = setTimeout(increment,time);
            }

            increment();
            //进度条停止与重新开始
            $("#stop").click(function () {
                if ("stop" == $("#stop").val()) {
                    //$("#prog").stop();
                    clearTimeout(st);
                    $("#prog").css("width","0%").text("等待启动");
                    $("#stop").val("start").text("重新开始");
                } else if ("start" == $("#stop").val()) {
                    increment();
                    $("#stop").val("stop").text("停止");
                }
            });
            //进度条暂停与继续
            $("#pause").click(function() {
                if ("pause" == $("#pause").val()) {
                    //$("#prog").stop();
                    clearTimeout(st);
                    $("#pause").val("goon").text("继续");
                } else if ("goon" == $("#pause").val()) {
                    increment();
                    $("#pause").val("stop").text("暂停");
                }
            });
        });
    </script>
</head>
<body>
<div class="container">
    <h3>
        采集进程...
    </h3>
    <div class="row clearfix">
        <div class="progress progress-striped active">
            <div id="prog" class="progress-bar" role="progressbar" aria-valuenow="" aria-valuemin="0" aria-valuemax="100" style="width:0%;">
                <span id="proglabel">正在启动，请稍后......</span>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-4 col-sm-6">
                <button id="pause" class="btn btn-primary" value="pause">暂停</button>
                <button id="stop" class="btn btn-primary" value="stop">停止</button>
                <!--<button id="goon" class="btn btn-primary">继续<button>-->
            </div>
        </div>
    </div>
</div>
</body>
</html>